package com.yyw.foodie.controller;

import com.yyw.foodie.common.Result;
import com.yyw.foodie.service.IndexSearch;
import com.yyw.foodie.utils.PagedGridResult;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author yiyw
 * @ClassName IndexController.java
 * @Description 首页搜索页
 * @createTime 2021年07月17日 13:27:00
 */
@RestController
@RequestMapping("/es")
public class IndexController {


    @Autowired
    private IndexSearch indexSearch;


    @GetMapping("/search")
    @ApiOperation(value = "根据关键字商品搜索", notes = "根据关键字搜索商品分页展示")
    public Result getItemsByPage(@ApiParam(value = "关键字") @RequestParam(value = "keywords", required = false) String keyWords,
                                 @ApiParam(value = "排序规则(默认=k/销量=c/价格=p)") @RequestParam(value = "sort", required = false, defaultValue = "k") String sort,
                                 @ApiParam(value = "显示条数") @RequestParam(value = "pageSize", required = false, defaultValue = "20") Integer pageSize,
                                 @ApiParam(value = "当前页") @RequestParam(value = "page", required = false, defaultValue = "1") Integer page) {
        PagedGridResult result = indexSearch.itemsPage(keyWords, sort, page, pageSize);
        return Result.ok(result);
    }
}
